package view 
{
	import com.greensock.TweenMax;
	import com.greensock.*;
	import com.greensock.plugins.*;
	import com.greensock.easing.*;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author bimkute
	 */
	public class Spin extends Base 
	{
		private var _arrNumberDialing:Array = [];
		private var _result:int;
		private var _count:int = 0;
		public function Spin(percent:int) 
		{
			addContent("Dial", "playGame");
			content.width = 3*this.width / 4;
			content.height = 3 * this.height / 4;
			
			var i:int;
			var j:int;
			
			var mc:MovieClip = content;
			//mảng chứa các selection của _dialing
			var arr:Array = [mc.selection1, mc.selection2, mc.selection3, mc.selection4, mc.selection5,  
								mc.selection6, mc.selection7, mc.selection8, mc.selection9,
								mc.selection10];
			_arrNumberDialing.push(arr);
			
			
			for (i = 0; i < _arrNumberDialing.length; i++) 
			{
				for (j = 0; j < _arrNumberDialing[i].length; j++) 
				{
					_arrNumberDialing[i][j].visible = false;
				}
			}
			
			content.txtPercent.text = String(percent) + " %";
			content.txtPercent.mouseEnabled = false;
		}
		
		public function dial(result:int):void 
		{
			_result = result;
			spin();
		}
		
		private function spin():void 
		{
			if (_count < 40) 
			{
				TweenMax.to(content.metal, .5, { rotation:360, ease:Linear.easeNone, 
												onComplete:spinStick});
			}
			else 
			{
				TweenMax.to(content.metal, 1, {rotation:360 + 35 * (_result - 1), ease:Back.easeInOut});
			}
			
			//TweenMax.to(_arrMetal[type], 5, {rotation:360, ease:Linear.easeNone});
			//squareTween.play();
		}
		
		private function spinStick():void //mc:MovieClip, result:int
		{
			spin();
		}
		
	}

}